﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;

namespace HNQXYJ.HN_User
{
    public partial class UserAddCounty : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string rankName = Session["ranklevel"].ToString();
                GetCountyNameBySession(rankName);
            }
            
        }

        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            Users user = new Users();
            user.UserName = this.txtUserName.Text.Trim();
            user.TrueName = this.txtTrueName.Text.Trim();
            user.Password = UsersBLL.GetMD5(this.txtPwd.Text.Trim());
            user.RankName = this.txtRankName.Text.Trim();
            user.RankLevel = this.HidCountyCode.Value;
            user.TouchMethod = this.txtTouchMehtod.Text;
            user.Notes = this.txtNotes.Text;
            user.AddDate = DateTime.Now;
            user.ErrTimes = 0;
            int res = new UsersBLL().AddNew(user);
            if (res > 0)
            {
                Response.Redirect("UserMgrCounty.aspx");
            }   
        }

        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("UserMgrCounty.aspx");
        }

        private void GetCountyNameBySession(string rankName)
        {
            
            HCounty county = new CountyBLL().GetCountyBySelfCode(rankName);
            this.txtRankName.Text = county.Name;
            this.HidCountyCode.Value = county.SelfCode;

        }
    }
}